import 'package:flutter/material.dart';
import 'package:secend_flutter/bottom_bar/travel_item_page.dart';
import 'package:secend_flutter/bottom_bar/home_item_page.dart';
import 'package:secend_flutter/bottom_bar/mine_item_page.dart';
import 'package:secend_flutter/bottom_bar/search_item_page.dart';
class IndexBar extends StatefulWidget {
  const IndexBar({Key? key}) : super(key: key);

  @override
  _IndexBarState createState() => _IndexBarState();
}

class _IndexBarState extends State<IndexBar> {
  final List<BottomNavigationBarItem> _bottoms=[
    const BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页',),
    const BottomNavigationBarItem(icon:  Icon(Icons.search),label: '搜索',),
    const BottomNavigationBarItem(icon: Icon(Icons.camera_alt_outlined),label: '旅拍',),
    const BottomNavigationBarItem(icon: Icon(Icons.person_outline),label: '我的',),
  ];

  int currentIndex=0;
  var currentPage;
  final List pageList=[
     const HomePage(),  SearchPage(hideLeft:true,
    ),const CameraPage(),  MinePage()
  ];
  @override
  Widget build(BuildContext context) {
    currentPage=pageList[currentIndex];
    return Scaffold(
      backgroundColor: Colors.white,
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        unselectedItemColor: Colors.black26,
        items: _bottoms,
        type: BottomNavigationBarType.fixed,
        currentIndex: currentIndex,
        onTap: (index){
          setState(() {
            currentIndex=index;
            currentPage=pageList[currentIndex];
          });
        },
        selectedItemColor:  Colors.amber,
      ),
      body: currentPage,
    );
  }
}
